package com.jvtd.eyl.ui.main.home.classInfo.classPeriodical;

import com.jvtd.eyl.base.BasePresenter;
import com.jvtd.eyl.bean.binding.ClassBean;
import com.jvtd.eyl.bean.binding.PeriodicalBean;
import com.jvtd.eyl.data.DbManager;
import com.jvtd.eyl.rxjava.JvtdRxSchedulers;
import com.jvtd.rxjava.JvtdObserverSubscriber;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.disposables.CompositeDisposable;

/**
 * 期刊二级分类信息
 * <p>
 * 作者:chenlei
 * 时间:2018/11/13 4:54 PM
 */
public class ClassPeriodicalPresenter<V extends ClassPeriodicalMvpView> extends BasePresenter<V>
        implements ClassPeriodicalMvpPresenter<V> {

    @Inject
    public ClassPeriodicalPresenter(DbManager dbManager, CompositeDisposable disposable) {
        super(dbManager, disposable);
    }

    @Override
    public void getClassPeriodicalList(String id, String sid) {
        if (!isAttachView()) return;
        getCompositeDisposable().add(getDbManager().getClassPeriodicalList(sid)
                .compose(JvtdRxSchedulers.handleObservableResult())
                .subscribeWith(new JvtdObserverSubscriber<List<PeriodicalBean>>(getMvpView()) {
                    @Override
                    public void onNext(List<PeriodicalBean> periodicalBeans) {
                        super.onNext(periodicalBeans);
                        if (isAttachView()) {
                            getMvpView().getClassPeriodicalListSuccess(periodicalBeans);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        if (isAttachView()) {
                            getMvpView().getClassPeriodicalListFailed();
                        }
                    }
                }));
    }
}
